import request from '../../utils/request'
interface getPhoneNumberDto {
  code: string
}
export interface AccessToken {
  access_token: string
}
export interface GetCodeSessionDto {
  grant_type: string
  appid: string
  secret: string
  js_code: string
}
export const getAccessToken = (appid: string, secret: string) => 
  request(`/api/wxapi/getAccessToken?grant_type=client_credential&appid=${appid}&secret=${secret}`, 'GET') as Promise<Result<AccessToken>>

export const getPhoneNumber = (access_token: string, data: getPhoneNumberDto) => 
  request(`/api/wxapi/getPhoneNumber?access_token=${access_token}`, 'POST', data) as Promise<Result<PhoneInfo>>

export interface WxSession {
  openid: string
  session_key: string
}

export const getCodeSession = (data: GetCodeSessionDto) => request(`/api/wxapi/getCodeSession`, 'POST', data) as Promise<Result<WxSession>>